package org.raymond.icloud.apis.admin.entity.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.Objects;

@Getter
public enum SexEnum {
    SECRET("SECRET", 0),
    MALE("MALE", 1),
    FEMALE("FEMALE", 2);

    @JsonValue
    private final String code;
    @EnumValue
    private final Integer value;

    SexEnum(String code, Integer value){
        this.code = code;
        this.value = value;
    }

    public static SexEnum getByCode(String code) {
        for (SexEnum e: SexEnum.values()) {
            if (Objects.equals(code, e.getCode())) {
                return e;
            }
        }
        return null;
    }

    public static SexEnum getByValue(Integer value) {
        for (SexEnum e: SexEnum.values()) {
            if (value==e.getValue()) {
                return e;
            }
        }
        return null;
    }
}
